#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL pre[maxn][30],suf[maxn][30];
LL premax[maxn],sufmax[maxn];
LL a[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n;cin>>n;
    for(LL i=0;i<n+10;i++){
        for(LL j=0;j<30;j++) pre[i][j]=suf[i][j]=0;
    }
    for(LL i=1;i<=n;i++) cin>>a[i];
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=26;j++){
            pre[i][j]=pre[i-1][j];
            if(a[i]==j) pre[i][j]++;
        }
    }
    for(LL i=n;i>=1;i--){
        for(LL j=1;j<=26;j++){
            suf[i][j]=suf[i+1][j];
            if(a[i]==j) suf[i][j]++;

        }
    }
    LL ans=0;
    for(LL l=1;l<=n;l++){
        for(LL r=l;r<=n;r++){

            LL sum1=0;
            for(LL k=1;k<=26;k++){
                sum1=max(sum1,pre[r][k]-pre[l-1][k]);
            }

            LL sum2=0;
            for(LL k=1;k<=26;k++){
                sum2=max(sum2,min(pre[l-1][k],suf[r+1][k]));
            }

            ans=max(ans,sum1+2*sum2);
        }
    }
    cout<<ans<<"\n";
  }
return 0;
}
